package com.leyou.item.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/spec")
public class SpecController {


    @Autowired
    private SpecService specService;

    /**
     * 跟分类id查询规格组
     * @param id
     * @return
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>>  findSpecGroupByCategoryId(@RequestParam("id") Long id){
        List<SpecGroupDTO> specGroupDTOList =   specService.findSpecGroupByCategoryId(id);
        return ResponseEntity.ok(specGroupDTOList);
    }

    /**
     * 跟规格组id或分类id查询规格参数
     * @param
     * @return
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>>  findSpecParamByCategoryIdOrGroupId(
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "gid",required = false) Long gid,
            @RequestParam(value = "searching",required = false) Boolean searching
    ){
        List<SpecParamDTO> specParamDTOList =   specService.findSpecParamByCategoryIdOrGroupId(cid,gid,searching);
        return ResponseEntity.ok(specParamDTOList);
    }


}
